package com.hfjyz.exam.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.hfjyz.exam.command.AdminLoginCommand;

public class AdminLoginValidator implements Validator {

	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	public boolean supports(Class clazz) {
		return clazz.isAssignableFrom(AdminLoginCommand.class);
	}

	@Override
	public void validate(Object target, Errors errors) {
		AdminLoginCommand cmd = (AdminLoginCommand) target;
		if (cmd.getAdminId() == null || cmd.getAdminId().trim().isEmpty()) {
			errors.rejectValue("adminId", "error.adminlogin.username",
					"请输入管理员帐号");
		}
		if (cmd.getAdminPassword() == null
				|| cmd.getAdminPassword().trim().isEmpty()) {
			errors.rejectValue("adminPassword", "error.adminlogin.password",
					"请输入管理员帐号");
		}
	}

}
